<?php 
	function getNextCaslNum($year,$database,$host,$login,$loginpassword){ 
		//Create connection. 
		$connect = 
				mysql_connect($host,$login,$loginpassword);	
		if (!$connect) {
			die('Could not connect: ' . mysql_error());
		}
		
		//Set-up and execute query.		
		mysql_select_db($database, $connect);		
		$query = "SELECT MAX(casl_no_sample) FROM sample_entry WHERE casl_no_year = '$year'";
		//echo $query;
		$analysis = mysql_query($query);
		$row = mysql_fetch_row($analysis) ;
		
		//Close connection.
		mysql_close($connect);
		
		//Check data generated.
		if ($row[0] == "") {
			return 1;
		} else {
			return $row[0]+1;
		}
		
	}





?>